#pragma once
#include<iostream>
#include<vector>
#include<unistd.h>

typedef void(* func_t)();  //函数指针，无参，第一个圆括号里面就是函数指针变量

void PrintLog()
{
    std::cout<<"pid: "<<getpid()<<",打印日制任务，正在被执行"<<std::endl;
}

void InsertMySQL()
{
    std::cout<<"pid: "<<getpid()<<",数据库任务，正在被执行"<<std::endl;
}

void NetRequest()
{
    std::cout<<"pid: "<<getpid()<<",执行网络请求任务，正在被执行"<<std::endl;
}

//约定，每一个command都必须是4字节
#define COMMAND_LOG 0
#define COMMAND_MYSQL 1
#define COMMAND_REQEUST 2

class Task
{
public:
    Task()
    {
        funcs.push_back(PrintLog);
        funcs.push_back(InsertMySQL);
        funcs.push_back(NetRequest);
    }
    void Execute(int command)
    {
        if(command>=0&&command<funcs.size())
         funcs[command]();
    }
    ~Task()
    {

    }
    public:
    std::vector<func_t> funcs;
};